package cn.xaut.数组;

public class demo27 {

    public int removeElement(int[] nums, int val) {

        int len = nums.length;
        if (len == 0)
            return 0;

        int index = 0;
        for (int i = 0; i < len; i++) {
            if (nums[i] != val)
                nums[index++] = nums[i];
        }

        return index;
    }

    public static void main(String[] args) {

        System.out.println(new demo27().removeElement(new int[]{3, 2, 2, 3}, 3));//2
        System.out.println(new demo27().removeElement(new int[]{0, 1, 2, 2, 3, 0, 4, 2}, 2));//5
    }
}
